<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<title>Client's orders list</title>
</h:head>
<body>
	<h:form id="form">
		<p:dataTable var="order" value="#{orderBean.getOrdersForClient()}"
			border="true">
			<p:column headerText="Order Id">
				<h:outputText value="#{order.orderId}" />
			</p:column>
			<p:column headerText="Client">
				<h:outputText value="#{order.client.name}" />
			</p:column>
			<p:column headerText="Order Description">
				<h:outputText value="#{order.orderDescription}" />
			</p:column>
			<p:column headerText="Price Per Item">
				<h:outputText value="#{order.pricePerItem}">
					<f:convertNumber type="currency" />
				</h:outputText>
			</p:column>
			<p:column headerText="Quantity">
				<h:outputText value="#{order.quantity}" />
			</p:column>
			<p:column headerText="Order Price">
				<h:outputText value="#{order.orderPrice}">
					<f:convertNumber type="currency" />
				</h:outputText>
			</p:column>
			<p:column headerText="Options">
				<p:commandButton action="#{orderBean.getOrderById(order.orderId)}"
					value="Edit" id="editOrderButton" update=":editForm:editOrder"
					oncomplete="edit.show();" />
				<p:commandButton action="#{orderBean.getOrderById(order.orderId)}"
					value="Delete" id="deleteOrderButton" icon="ui-icon-circle-close"
					update=":deleteForm:deleteOrder" oncomplete="remove.show();" />
			</p:column>
		</p:dataTable>

		<p:commandButton id="makeOrderButton" type="button"
			update=":addForm:addOrder" onclick="add.show();" value="Make order"
			action="#{orderBean.create}" />
	</h:form>

	<h:form id="addForm">
		<p:dialog id="addOrder" header="Make order" widgetVar="add"
			modal="true" resizable="false">

			<h:panelGrid columns="2">

				<h:outputLabel for="clientId" value="Client Id: " />
				<h:outputText id="clientId" value="#{orderBean.client.clientId}"
					label="clientId" />

				<h:outputLabel for="orderDescription" value="Order Description: " />
				<p:inputTextarea id="orderDescription"
					value="#{orderBean.order.orderDescription}"
					label="orderDescription" required="true" />

				<h:outputLabel for="pricePerItem" value="Price Per Item: " />
				<p:inputText id="pricePerItem"
					value="#{orderBean.order.pricePerItem}" label="pricePerItem"
					required="true" />

				<h:outputLabel for="quantity" value="Quantity: " />
				<p:inputText id="quantity" value="#{orderBean.order.quantity}"
					label="quantity" required="true" />

			</h:panelGrid>

			<p:commandButton action="#{orderBean.add}" value="Save"
				update=":form" oncomplete="add.hide();" icon="ui-icon-check" />

			<p:commandButton value="Cancel" onclick="add.hide();"
				icon="ui-icon-close" />

		</p:dialog>
	</h:form>

	<h:form id="editForm">
		<p:dialog id="editOrder" header="Edit order" widgetVar="edit"
			modal="true" resizable="false">

			<h:inputHidden id="clientId" value="#{orderBean.client.clientId}" />
			<h:panelGrid columns="2">

				<h:outputLabel for="id" value="Id: " />
				<h:outputText id="id" value="#{order.orderId}" label="id" />

				<h:outputLabel for="client" value="Client: " />
				<h:outputText id="client" value="#{orderBean.client.name}"
					label="client" required="true" />

				<h:outputLabel for="orderDescription" value="Order Description: " />
				<p:inputTextarea id="orderDescription"
					value="#{orderBean.order.orderDescription}"
					label="orderDescription" required="true" />

				<h:outputLabel for="pricePerItem" value="Price Per Item: " />
				<p:inputText id="pricePerItem"
					value="#{orderBean.order.pricePerItem}" label="pricePerItem"
					required="true" />

				<h:outputLabel for="quantity" value="Quantity: " />
				<p:inputText id="quantity" value="#{orderBean.order.quantity}"
					label="quantity" required="true" />

				<h:outputLabel for="orderPrice" value="Order Price: " />
				<p:inputText id="orderPrice" value="#{orderBean.order.orderPrice}"
					label="orderPrice" required="true" />

			</h:panelGrid>

			<p:commandButton action="#{orderBean.update}" value="Save"
				update=":form" oncomplete="edit.hide();" icon="ui-icon-check"/>

			<p:commandButton value="Cancel" onclick="edit.hide();"
				icon="ui-icon-close" />

		</p:dialog>
	</h:form>

	<h:form id="deleteForm">
		<p:dialog id="deleteOrder"
			header="Are you sure you want to delete this order?"
			widgetVar="remove" modal="true" resizable="false">

			<h:panelGrid columns="2">

				<h:outputLabel for="id" value="Id: " />
				<h:outputText id="id" value="#{order.orderId}" label="id" />

				<h:outputLabel for="client" value="Client: " />
				<h:outputText id="client" value="#{orderBean.client.name}"
					label="client" required="true" />

				<h:outputLabel for="orderDescription" value="Order Description: " />
				<h:outputText id="orderDescription"
					value="#{order.orderDescription}" label="orderDescription"
					required="true" />

				<h:outputLabel for="pricePerItem" value="Price Per Item: " />
				<h:outputText id="pricePerItem" value="#{order.pricePerItem}"
					label="pricePerItem" required="true" />

				<h:outputLabel for="quantity" value="Quantity: " />
				<h:outputText id="quantity" value="#{order.quantity}"
					label="quantity" required="true" />

				<h:outputLabel for="orderPrice" value="Order Price: " />
				<h:outputText id="orderPrice" value="#{order.orderPrice}"
					label="orderPrice" required="true" />

			</h:panelGrid>

			<p:commandButton action="#{orderBean.delete}" value="Delete"
				update=":form" oncomplete="delete.hide();"
				icon="ui-icon-circle-close" />

			<p:commandButton value="Cancel" onclick="delete.hide();"
				icon="ui-icon-close" />

		</p:dialog>
	</h:form>

</body>
</html>